package puj.news.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import puj.news.dto.Noticia;
import puj.news.util.General;

/**
 * Servlet implementation class ExtractDetail
 */
@WebServlet("/extractdetail")
public class ExtractDetail extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ExtractDetail() {
		super();

	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String usuario = " ";
		
		String idnota = " ";

		try {
			usuario = (String) request.getParameter("usuario");
			idnota = (String) request.getParameter("idnota");

			request.setCharacterEncoding("UTF-8");

			response.setCharacterEncoding("UTF-8");

			response.setContentType("application/json");
			
			Noticia news=(Noticia)Extractnews.noticiasRepo.get(idnota);
			
			Gson gson = new Gson();
			
			String json = gson.toJson(news);					
			
			response.getOutputStream().println(json);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

}
